package com.sgx.learning.luban.homework.constantpool;

import lombok.Data;

import java.io.IOException;
import java.io.InputStream;

@Data
public abstract class ConstantPoolInfo {
    public final static byte TAG_C_UTF8_INFO = 1;
    public final static byte TAG_C_INTEGER_INFO = 3;
    public final static byte TAG_C_FLOAT_INFO = 4;
    public final static byte TAG_C_LONG_INFO = 5;
    public final static byte TAG_C_DOUBLE_INFO = 6;
    public final static byte TAG_C_CLASS_INFO = 7;
    public final static byte TAG_C_STRING_INFO = 8;
    public final static byte TAG_C_FIELDREF_INFO = 9;
    public final static byte TAG_C_METHODREF_INFO = 10;
    public final static byte TAG_C_INTERFACEMETHODREF_INFO = 11;
    public final static byte TAG_C_NAMEANDTYPE_INFO = 12;

    private short tag;

    public abstract void read(InputStream is) throws IOException;

    public String getTagString() {
        String back = "";
        switch (tag) {
            case TAG_C_UTF8_INFO : back = "Utf8";break;
            case TAG_C_INTEGER_INFO : back = "Integer";break;
            case TAG_C_FLOAT_INFO : back = "Float";break;
            case TAG_C_LONG_INFO : back = "Long";break;
            case TAG_C_DOUBLE_INFO : back = "Double";break;
            case TAG_C_CLASS_INFO : back = "Class";break;
            case TAG_C_STRING_INFO : back = "String";break;
            case TAG_C_FIELDREF_INFO : back = "FieldRef";break;
            case TAG_C_METHODREF_INFO : back = "MethodRef";break;
            case TAG_C_INTERFACEMETHODREF_INFO : back = "InterfaceMethodRef";break;
            case TAG_C_NAMEANDTYPE_INFO : back = "NameAndType";break;
            default:break;
        }
        return back;
    }
}
